﻿using System.Collections.Generic;
using UnityEngine;

public abstract class BaseState
{
    public FSM fsm;
    public AI_State mState;
    public string stateName;
    public List<BaseState> stateList = new List<BaseState>();

    public virtual string GetName()
    {
        return stateName;
    }

    public void Init(FSM fsm)
    {
        this.fsm = fsm;
        DoInit();
    }

    public void Enter()
    {
        DoEnter();
    }

    public void Exit()
    {
        fsm.lastStateName = stateName;
        DoExit();
    }

    public abstract void DoInit();
    public abstract bool CheckEnter();
    public abstract bool CheckExit();
    public abstract void DoEnter();
    public abstract void DoExit();
    public abstract void Run(float dt);

    public void AddState(params BaseState[] states)
    {
        stateList.AddRange(states);
    }

    public BaseState NextState()
    {
        BaseState state = null;
        for (int i = 0, len = stateList.Count; i < len; i++)
        {
            if (stateList[i].CheckEnter())
            {
                state = stateList[i];
                break;
            }
        }
        return state;
    }
}